package cn.humaohua.study.yanmo_design_pattern.ch14.v3;

import cn.humaohua.study.yanmo_design_pattern.ch14.v1.Aggregate;
import cn.humaohua.study.yanmo_design_pattern.ch14.v1.Iterator;
import cn.humaohua.study.yanmo_design_pattern.ch14.v2.PayModel;

public class SalaryManager extends Aggregate {
    private PayModel[] pms = null;

    public PayModel[] getPays() {
        return pms;
    }

    public void calcSalary() {
        PayModel pm1 = new PayModel();
        pm1.setPay(2200);
        pm1.setUserName("wang5");

        PayModel pm2 = new PayModel();
        pm2.setPay(3600);
        pm2.setUserName("zhang6");

        pms = new PayModel[2];
        pms[0] = pm1;
        pms[1] = pm2;
    }

    public int size() {
        return pms.length;
    }

    public Object get(int index) {
        if (index < this.pms.length)
            return pms[index];
        return null;
    }

    @Override
    public Iterator createIterator() {
        return new ArrayIteratorImpl(this);
    }
}
